<?php
/**
 * Created by PhpStorm.
 * User: Victor
 * Date: 2018/11/6
 * Time: 11:06
 */
$yh_id = isset($_GET['data']) ? $_GET['data'] : 'sms';
$url = "http://qr.liantu.com/api.php?text=http://192.168.0.176/tiaozhuan.php?name=".$yh_id."%26ib_id=1";
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>

<div class="middle">

    <div class="login_div">
        <div class="change_div">
            <div class="con_bottom">
                <div id="code">
                    <div class="code_div">
                        <img src='<?php echo $url ?>' id="qrcodeimg" width="144px" height="145px"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        var src = $('#qrcodeimg')[0].src;
        console.log(src);
                    var min=0;

                    interval1= setInterval(function () {
                        min=min+1000;

                        $.ajax({
                            type: "GET",
                            url: "checkqruuid.php",
                            data: {'id': 2},
                            success: function (result) {

                                min=min+1000;
                                if(min==36000){
                                    console.log(min);
                                    alert("二维码已过期！");
                                    clearInterval(interval1);
                                    location.replace(location.href);
                                    min=1000;
                                    interval1();
                                }else{
                                    console.log(min);
                                    var data = JSON.parse(result);
                                    if (data.code == 1) {
                                        // alert('扫码成功（即登录成功），进行跳转.....');
                                        //停止轮询
                                        clearInterval(interval1);
                                        location.href="index.html";
                                        //TODO 拿到需要的信息 然后跳转什么的
                                    }else if(data.code == 0){
                                        alert(data.msg);
                                        //停止轮询
                                        clearInterval(interval1);
                                        location.href="ceshi.html";
                                    }
                                }

                            }
                        });

                    }, 1000);//1秒钟  频率按需求

    });
</script>
</body>
</html>
